package com.company.iterator;

import java.util.ArrayList;
import java.util.List;

/**
 * 具体聚合角色，车库
 */
public class CarGarageAggregate implements Aggregate {

    private List<Car> carList;


    public CarGarageAggregate() {
        this.carList = new ArrayList<>();
    }

    public Car get(int index) {
        return carList.get(index);
    }

    public void add(Car car) {
        carList.add(car);
    }

    public int length() {
        return carList.size();
    }

    public void remove(Car car){
        carList.remove(car);
    }

    public Iterator iterator() {
        return new CarGarageIterator(this);
    }
}
